﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using HslCommunication;
using Helpers;
using System.Threading;
using System.ServiceModel;
using HslCommunication.Profinet.Inovance;
using Function;
using Oracle.ManagedDataAccess.Client; 
using System.Data;
using DbHelper;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
using Print.printServer;
using System.IO;
using System.Runtime.Remoting.Contexts;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace ShenMaPrint {
    public partial class Form1 : Form {
        private MyOracleDataAccess dataAccessMain;
        private string conStr;
        public bool IsLand = false;

        // string PassWoard = "";
        string MacNO = "";
        string Nowkind = "";
        // string PalletCode = "";
        string PLCIP = ""; 
        int GlueNo = 0;
        public static Form2 f2;
        public static bool changed = false;
 
    
        public static Form5 f5;
        public static Form6 f6;
    
   
        Thread th_RunMain;
        public Form1() {
            InitializeComponent();
             
            CheckForIllegalCrossThreadCalls = false;

            LogHelper.SaveLog("开始", LogHelper.LogType.PLC, "main");
        }
        public void frm1_Load(object sender, EventArgs e) {
            try {
                GetInfo();
            
                th_RunMain = new Thread(new ThreadStart(RunMain));
                th_RunMain.IsBackground = true;
                th_RunMain.Start(); 
            } catch (Exception) {
            }

        }
        public void GetInfo() {
            //获取AGVMS数据库连接-------------------------------------------------------------------------
            SystemParamsHelper.DBConnectionString = INIFileHelper.ReadIniValue("DB", "CONNECTIONSTRING", Application.StartupPath + @"\Setting.ini").Trim();
            PRFunction.GetDBConnectionString(SystemParamsHelper.DBConnectionString);

            conStr = INIFileHelper.ReadIniValue("DB", "CONNECTIONSTRING", Application.StartupPath + @"\Setting.ini").Trim();
            dataAccessMain = new MyOracleDataAccess(conStr);

            Name = INIFileHelper.ReadIniValue("Setting", "Name", Application.StartupPath + @"\Setting.ini").Trim();
            textBox1.Text = INIFileHelper.ReadIniValue("Setting", "gap", Application.StartupPath + @"\Setting.ini").Trim();
            textBox3.Text = INIFileHelper.ReadIniValue("Setting", "width", Application.StartupPath + @"\Setting.ini").Trim();
            textBox2.Text = INIFileHelper.ReadIniValue("Setting", "heigth", Application.StartupPath + @"\Setting.ini").Trim();
            MacNO = INIFileHelper.ReadIniValue("Setting", "MacNO", Application.StartupPath + @"\Setting.ini").Trim();
            Nowkind = INIFileHelper.ReadIniValue("Setting", "Nowkind", Application.StartupPath + @"\Setting.ini").Trim();
            GlueNo = int.Parse(INIFileHelper.ReadIniValue("Setting", "GlueNo", Application.StartupPath + @"\Setting.ini").Trim());
            PLCIP = INIFileHelper.ReadIniValue("PLC", "IP", Application.StartupPath + @"\Setting.ini").Trim();
            label6.Text = MacNO;
            label2.Text = Nowkind;
            if (IsLand) {
                label8.Text = Name;
            } else {
                label8.Text = "无";
            }
        }

        string getQNo() {
            GlueNo += 1;
            INIFileHelper.WriteIniValue("Setting", "GlueNo", GlueNo.ToString(), Application.StartupPath + @"\Setting.ini");

            string QNo;
            if (GlueNo < 10) {
                QNo = "000" + GlueNo;
            } else if (GlueNo < 100) {
                QNo = "00" + GlueNo;
            } else if (GlueNo < 1000) {
                QNo = "0" + GlueNo;
            } else if (GlueNo < 10000) {
                QNo = GlueNo.ToString();
            } else {
                //条码大于9999，重置为1
                INIFileHelper.WriteIniValue("Setting", "GlueNo", "1", Application.StartupPath + @"\Setting.ini");
                GlueNo = 1;
                QNo = "0001";
            }
            string codeQ = MacNO + "-" + QNo;
            return codeQ;
        }

        public void RunMain() {

            while (true) {
                Thread.Sleep(200);
                try {
                   doAction();
                } catch (Exception e) {
                    String m = e.StackTrace;
                    LogHelper.SaveLog("Error:" + e.ToString() + "\r\n"+m+"\r\n", LogHelper.LogType.ErrorInfo, "Error");
                }
            }  
        }
        void doAction() {
            this.label19.Text = "start read ";
            //收到称重信号
            if (WeighOver()) {
                jiaokind();
                changeBatchNo();
                string NowkindCode= readFile(Nowkind);
                if (NowkindCode == null) {

                    this.label19.Text = Nowkind+"无编码"; 
                    LogHelper.SaveLog(DateTime.Now.ToString() + "无编码" + Nowkind, LogHelper.LogType.RecDataState, "打印记录");
                    Thread.Sleep(1000);
                    return;
                }
                this.label19.Text = "read finsh";
                string codeQ = getQNo(); 
                string dn = DateTime.Now.Date.ToString("yyyy-MM-dd");
                String zl = getZl();
                this.label19.Text = "打印中";
                PrintLabel(codeQ, zl + "KG", dn,  Nowkind);
                LogHelper.SaveLog(DateTime.Now.ToString() + "触发称重，栈板： Q" + dn  + "胶种：" + Nowkind + ",胶块码：" + codeQ + ",重量" + zl + "KG", LogHelper.LogType.RecDataState, "打印记录");
                SendWight(); 
                
                //PRFunction.PR_Insert_TaskInfoInit_AndType(codeQ, Nowkind, zl);
                dataAccessMain.ExecuteNonQuery_Text(

                                    @"Insert into MES_KPWIPRUNCARD_R   (ORGID,KPSN,PARTNO,QTY)   VALUES   (:ORGID,:KPSN,:PARTNO,:QTY)",
                                        new OracleParameter[]
                                {
                                            MyOracleDataAccess.CreateParameter("ORGID", OracleDbType.Int32, 3201),
                                            MyOracleDataAccess.CreateParameter("KPSN", OracleDbType.NVarchar2, codeQ),
                                            MyOracleDataAccess.CreateParameter("PARTNO", OracleDbType.NVarchar2, NowkindCode),
                                            MyOracleDataAccess.CreateParameter("QTY", OracleDbType.Double, zl)
                                });
                LogHelper.SaveLog("已录入" + "\r\n", LogHelper.LogType.Other, "录入");

            }
        }

       String  readFile(String Nowkind) {
            string filePath = "kindCode.txt";
            List<string> lines = new List<string>();
            using (StreamReader reader = new StreamReader(filePath)) {
                string line;
                while ((line = reader.ReadLine()) != null) {
                    String[] kv=line.Split(',');
                    if (kv[0] == Nowkind) {
                        if (kv.Length > 1) {
                            return kv[1];
                        }
                       
                    }
                    
                }
            }

            return null;

        }

       String  getZl() {
            string zlNO = ReadWight();
            double a = (double)int.Parse(zlNO) / 10;
            string zl = a.ToString();
            return zl;
        }

        public class TSCLIB_DLL {
            [DllImport("TSCLIB.dll", EntryPoint = "about")]
            public static extern int about();

            [DllImport("TSCLIB.dll", EntryPoint = "openport")]
            public static extern int openport(string printername);

            [DllImport("TSCLIB.dll", EntryPoint = "barcode")]
            public static extern int barcode(string x, string y, string type,
                        string height, string readable, string rotation,
                        string narrow, string wide, string code);

            [DllImport("TSCLIB.dll", EntryPoint = "clearbuffer")]
            public static extern int clearbuffer();

            [DllImport("TSCLIB.dll", EntryPoint = "closeport")]
            public static extern int closeport();

            [DllImport("TSCLIB.dll", EntryPoint = "downloadpcx")]
            public static extern int downloadpcx(string filename, string image_name);

            [DllImport("TSCLIB.dll", EntryPoint = "formfeed")]
            public static extern int formfeed();

            [DllImport("TSCLIB.dll", EntryPoint = "nobackfeed")]
            public static extern int nobackfeed();

            [DllImport("TSCLIB.dll", EntryPoint = "printerfont")]
            public static extern int printerfont(string x, string y, string fonttype,
                            string rotation, string xmul, string ymul,
                            string text);

            [DllImport("TSCLIB.dll", EntryPoint = "printlabel")]
            public static extern int printlabel(string set, string copy);

            [DllImport("TSCLIB.dll", EntryPoint = "sendcommand")]
            public static extern int sendcommand(string printercommand);

            [DllImport("TSCLIB.dll", EntryPoint = "setup")]
            public static extern int setup(string width, string height,
                      string speed, string density,
                      string sensor, string vertical,
                      string offset);

            [DllImport("TSCLIB.dll", EntryPoint = "windowsfont")]
            public static extern int windowsfont(int x, int y, int fontheight,
                            int rotation, int fontstyle, int fontunderline,
                            string szFaceName, string content);

        }

        public string DateToString() {
            string d = DateTime.Now.Year + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            return d;
        }


        void setUp() {
            TSCLIB_DLL.openport("Bar Code Printer T-4503E");
            if (changed) {
                // 设置标签 宽度、高度 等信息.
                // 宽 94mm  高 25mm
                // 速度为4
                // 字体浓度为8
                // 使用垂直間距感測器(gap sensor)
                // 两个标签之间的  间距为 3.5mm
                string jiange = this.textBox1.Text;
                string gaodu = this.textBox2.Text;
                string kuandu = this.textBox3.Text;
                TSCLIB_DLL.setup(gaodu, kuandu, "4", "10", "0", jiange, "0");
                TSCLIB_DLL.sendcommand("DIRECTION 1");

                // 清除缓冲信息
                TSCLIB_DLL.clearbuffer();

                TSCLIB_DLL.sendcommand("CLS");
                changed = true;
            }
            
        }

       

        public void PrintLabel(string code, string zhongliang, string today, string jiaokind) {
            if (INIFileHelper.ReadIniValue("Setting", "newPrint", Application.StartupPath + @"\Setting.ini").Trim()=="1") {
                new Code128Printer().print(code, zhongliang, today, jiaokind);
                return;
            }
         
            try {
                #region 打印
                String jihuaTimeTextX = INIFileHelper.ReadIniValue("Setting", "jihuaTimeTextX", Application.StartupPath + @"\Setting.ini").Trim();
                String jihuaTimeTextY = INIFileHelper.ReadIniValue("Setting", "jihuaTimeTextY", Application.StartupPath + @"\Setting.ini").Trim();
                String jihuaTimeX = INIFileHelper.ReadIniValue("Setting", "jihuaTimeX", Application.StartupPath + @"\Setting.ini").Trim();
                String jihuaTimeY = INIFileHelper.ReadIniValue("Setting", "jihuaTimeY", Application.StartupPath + @"\Setting.ini").Trim();
                String shixiaoTimeTextX = INIFileHelper.ReadIniValue("Setting", "shixiaoTimeTextX", Application.StartupPath + @"\Setting.ini").Trim();
                String shixiaoTimeTextY = INIFileHelper.ReadIniValue("Setting", "shixiaoTimeTextY", Application.StartupPath + @"\Setting.ini").Trim();
                String shixiaoTimeX = INIFileHelper.ReadIniValue("Setting", "shixiaoTimeX", Application.StartupPath + @"\Setting.ini").Trim();
                String shixiaoTimeY = INIFileHelper.ReadIniValue("Setting", "shixiaoTimeY", Application.StartupPath + @"\Setting.ini").Trim();
                String zhongliangX = INIFileHelper.ReadIniValue("Setting", "zhongliangX", Application.StartupPath + @"\Setting.ini").Trim();
                String zhongliangY = INIFileHelper.ReadIniValue("Setting", "zhongliangY", Application.StartupPath + @"\Setting.ini").Trim();
                String codeX = INIFileHelper.ReadIniValue("Setting", "codeX", Application.StartupPath + @"\Setting.ini").Trim();
                String codeY = INIFileHelper.ReadIniValue("Setting", "codeY", Application.StartupPath + @"\Setting.ini").Trim();
                String pichiX = INIFileHelper.ReadIniValue("Setting", "pichiX", Application.StartupPath + @"\Setting.ini").Trim();
                String pichiY = INIFileHelper.ReadIniValue("Setting", "pichiY", Application.StartupPath + @"\Setting.ini").Trim();
                this.textBox4.Text = codeX;
                this.textBox5.Text = codeY;
                //TSCLIB_DLL.openport("Bar Code Printer T-4503E");     //Open specified printer driver
                setUp();
               

                string command = "QRCODE 30,45,H,4,A,0,M2,S5,\"" + code + "\"";
                TSCLIB_DLL.sendcommand(command);
                
                DateTime Sxrq = DateTime.Now;
                string SxrqAdd = Sxrq.AddDays(50).Date.ToString("yyyy-MM-dd");
                TSCLIB_DLL.windowsfont(int.Parse(jihuaTimeTextX), int.Parse(jihuaTimeTextY), 20, 0, 2, 0, "宋体", "计划日期:");
                TSCLIB_DLL.windowsfont(int.Parse(jihuaTimeX), int.Parse(jihuaTimeY), 30, 0, 2, 0, "宋体", today);
                TSCLIB_DLL.windowsfont(int.Parse(shixiaoTimeTextX), int.Parse(shixiaoTimeTextY), 20, 0, 2, 0, "宋体", "失效日期:");
                TSCLIB_DLL.windowsfont(int.Parse(shixiaoTimeX), int.Parse(shixiaoTimeY), 30, 0, 2, 0, "宋体", SxrqAdd);

                TSCLIB_DLL.windowsfont(int.Parse(zhongliangX), int.Parse(zhongliangY), 30, 0, 2, 0, "宋体", zhongliang);

                TSCLIB_DLL.windowsfont(588, 30, 30, 0, 2, 0, "宋体", jiaokind);

                TSCLIB_DLL.windowsfont(int.Parse(pichiX), int.Parse(pichiY), 30, 0, 2, 0, "宋体", code);
                TSCLIB_DLL.barcode(codeX, codeY, "128", "60", "0", "0", "3", "4", code);
                // 打印.
                TSCLIB_DLL.printlabel("1", "1");
                TSCLIB_DLL.sendcommand("CLS");
                LogHelper.SaveLog("打印完成", LogHelper.LogType.RecDataState, "打印记录");

                // 关闭 打印机 端口
                TSCLIB_DLL.closeport();
                #endregion
            } catch (Exception ex) {
                LogHelper.SaveLog("Error:" + ex.ToString() + "\r\n", LogHelper.LogType.ErrorInfo, "ErrorPrint");
            }
        }
        InovanceAMTcp inovanceAMTcp = null;

        public bool getInovanceAMTcp() {
            while (true) {

                if (inovanceAMTcp == null) {
                    this.label19.Text = "新连接 " + PLCIP;
                    inovanceAMTcp = new InovanceAMTcp(PLCIP, 502);
                    OperateResult connect = inovanceAMTcp.ConnectServer();
                    if (!connect.IsSuccess) {
                        this.label19.Text = connect.Message + "连接plc 失败 ";
                        Close502();
                        Thread.Sleep(500);
                    } else {
                        LogHelper.SaveLog("链接成功"  , LogHelper.LogType.RecDataState, "称重记录");
                        this.label19.Text = "链接成功 ";
                        return true;
                       
                    }
                }
                return true;
            }

           

            
        }
        int i = 1;
        public bool WeighOver()//称重完成信号
        {
         
            try {
                DateTime dtStart = DateTime.Now;

                i = 1;
                while (true) {
                    Thread.Sleep(10); 
                     getInovanceAMTcp(); 
                    //读取开始打印信号
                    var printSign = inovanceAMTcp.ReadInt16("MW30", 2); 
                    if (!printSign.IsSuccess) { 
                        Close502();
                        LogHelper.SaveLog(printSign.Message+"PLC读取MW30失败\r\n", LogHelper.LogType.RecDataState, "称重记录");
                        Thread.Sleep(500);
                        continue;
                    } 
                    int printSignT = (int)printSign.Content[1];
                    //查询PLC打印信号，1开始打印
                    if (printSignT == 1) { 
                        LogHelper.SaveLog("查询PLC打印信号，开始打印标志:" + printSignT, LogHelper.LogType.RecDataState, "称重记录");
                        return true;
                    } else {
                        this.label19.Text = "没有打印标志 " +i++;
                        
                    }

                }
              
            } catch (Exception ex) {
                LogHelper.SaveLog("Error:" + ex.Message + "\r\n", LogHelper.LogType.ErrorInfo, "Error");
                return false;
            }
        
        }

       void  jiaokind() {
         
            OperateResult<ushort[]> res= inovanceAMTcp.ReadUInt16("MW5800", 20);
            if (!res.IsSuccess) {
                Close502();
                LogHelper.SaveLog(res.Message +"PLC读取 一线MW5800失败\r\n", LogHelper.LogType.RecDataState, "称重记录");
                Thread.Sleep(500);
                return ;
            }
            List<byte> r = new List<byte>();
            foreach (var d in res.Content) {
                if (d != 0) {
                    r.Add((byte)d);
                }
            }
            Nowkind= System.Text.Encoding.UTF8.GetString(r.ToArray());

            INIFileHelper.WriteIniValue("Setting", "Nowkind", Nowkind, Application.StartupPath + @"\Setting.ini");
            label2.Text = Nowkind;
        }
        void changeBatchNo() {
         
            OperateResult<ushort[]> res = inovanceAMTcp.ReadUInt16("MW5700", 20);
            if (!res.IsSuccess) {
                Close502();
                LogHelper.SaveLog(res.Message+"PLC读取MW5400失败\r\n", LogHelper.LogType.RecDataState, "称重记录");
                Thread.Sleep(500);
                return;
            }
            List<byte> r = new List<byte>();
            foreach (var d in res.Content) {
                if (d != 0) {
                    r.Add((byte)d);
                }
            }
           var newMacNO = System.Text.Encoding.UTF8.GetString(r.ToArray());
            if (newMacNO != MacNO) {
             
                INIFileHelper.WriteIniValue("Setting", "MacNO", newMacNO, Application.StartupPath + @"\Setting.ini");
                INIFileHelper.WriteIniValue("Setting", "GlueNo", "0", Application.StartupPath + @"\Setting.ini");
                MacNO = newMacNO;
                GlueNo = 0;
                label6.Text = MacNO;
            }
        
        }

        public string ReadWight()//当前胶块重量
        {
 
            string wight = "";

            try {
                bool PLCconnect = true;
                while (PLCconnect) {
                    Thread.Sleep(10);

                    //第一位写入1（打印完成），第二位读到1（开始打印）
                    getInovanceAMTcp();
                   
                  

                    LogHelper.SaveLog("进入：2", LogHelper.LogType.RecDataState, "称重记录");
                    //读取重量
                    var Weigh = inovanceAMTcp.ReadInt16("MW2710");
                    if (Weigh.IsSuccess) {
                        //称重完成，回复完成信号
                        if (inovanceAMTcp.Write("MW30", (ushort)1).IsSuccess) {
                            PLCconnect = false;
                            //成功读取
                            wight = Weigh.Content.ToString();
                            LogHelper.SaveLog("称重完成，回复称重完成信号成功", LogHelper.LogType.RecDataState, "称重记录");
                            return wight;
                        }

                    } else {
                        Close502();
                        LogHelper.SaveLog(Weigh.Message+"PLC读取MW2710失败\r\n", LogHelper.LogType.RecDataState, "称重记录");
                        Thread.Sleep(500);
                        continue;
                    }


                }
                return wight;
            } catch (Exception ex) {

                LogHelper.SaveLog("Error:" + ex.Message + "\r\n", LogHelper.LogType.ErrorInfo, "Error");
                return wight;
            }
        }

        public void SendWight()//当前胶块重量
        {
            try {
                while (true) {
                    //第一位写入1（打印完成），第二位读到1（开始打印）
                    getInovanceAMTcp();
                   
                    Thread.Sleep(10);
                  

                    //读取重量称重信号
                    var printSigns = inovanceAMTcp.ReadInt16("MW30", 2);
                    if (printSigns.IsSuccess) {
                        Thread.Sleep(20);
                        int printSignK = (int)printSigns.Content[0];
                        if (printSignK != 0) {
                            //称重完成，回复完成信号
                            if (inovanceAMTcp.Write("MW30", (ushort)0).IsSuccess) {
                              
                                LogHelper.SaveLog("打印完成，回复打印完成信号成功", LogHelper.LogType.RecDataState, "称重记录");
                                Thread.Sleep(10);
                                return;
                            }
                        }
                    } else {
                        Close502();
                        LogHelper.SaveLog(printSigns.Message+"PLC写MW30失败\r\n", LogHelper.LogType.RecDataState, "称重记录");
                        Thread.Sleep(500);
                        continue;
                    }



                }
            } catch (Exception ex) {
                LogHelper.SaveLog("Error:" + ex.Message + "\r\n", LogHelper.LogType.ErrorInfo, "Error");
            }
          
        }


        void Close502() {
            if(inovanceAMTcp != null) {
                try {
                    inovanceAMTcp.ConnectClose();
                   
                    LogHelper.SaveLog("断开链接", LogHelper.LogType.RecDataState, "称重记录");
                } catch (Exception e) {
                    LogHelper.SaveLog("断开链接失败"+e.Message, LogHelper.LogType.RecDataState, "称重记录");
                }
              
            }
            inovanceAMTcp = null;
        }


        private void button3_Click(object sender, EventArgs e) {
            string fileName = Application.StartupPath + @"\Log\" + DateTime.Now.ToString("yyyy_MM_dd");
            try {
                System.Diagnostics.Process.Start(fileName);
            } catch {
                string str = "今日暂无此日志";
                MessageBox.Show(str, "Tips", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }

        }

        

        
        private void button6_Click(object sender, EventArgs e) {
            if (f2 == null) {
                f2 = new Form2(this);
                f2.Show();
            } else {
                f2.Activate();
            }
        }

        private void button7_Click(object sender, EventArgs e) {
            IsLand = false;
            GetInfo();
        }

        private void button1_Click(object sender, EventArgs e) {
            string fileName = Application.StartupPath + @"\Log\" + DateTime.Now.ToString("yyyy_MM_dd") + @"\" + LogHelper.LogType.ErrorInfo;
            try {
                System.Diagnostics.Process.Start(fileName);
            } catch {
                string str = "今日暂无此日志";
                MessageBox.Show(str, "Tips", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void button2_Click(object sender, EventArgs e) {
            string fileName = Application.StartupPath + @"\Log\" + DateTime.Now.ToString("yyyy_MM_dd") + @"\" + LogHelper.LogType.RecDataState;
            try {
                System.Diagnostics.Process.Start(fileName);
            } catch {
                string str = "今日暂无此日志";
                MessageBox.Show(str, "Tips", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void button8_Click(object sender, EventArgs e) {
            if (IsLand) {
                if (f5 == null) {
                    f5 = new Form5(this);
                    f5.Show();
                } else {
                    f5 = new Form5(this);
                    f5.Show();
                    f5.Activate();
                }
            } else {
                if (MessageBox.Show("请先登陆！", "警告！", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
                    if (f2 == null) {
                        f2 = new Form2(this);
                        f2.Show();
                    } else {
                        f2.Activate();
                    }
                }
            }
        }

        private void button10_Click(object sender, EventArgs e) {
            if (IsLand) {
                if (f6 == null) {
                    f6 = new Form6(this);
                    f6.Show();
                } else {
                    f6 = new Form6(this);
                    f6.Show();
                    f6.Activate();
                }
            } else {
                if (MessageBox.Show("请先登陆！", "警告！", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
                    if (f2 == null) {
                        f2 = new Form2(this);
                        f2.Show();
                    } else {
                        f2.Activate();
                    }
                }
            }
        }

        private void button9_Click(object sender, EventArgs e) {

        }

        private void textBox1_TextChanged(object sender, EventArgs e) {
    

            INIFileHelper.WriteIniValue("Setting", "gap", textBox1.Text, Application.StartupPath + @"\Setting.ini");
            changed = true;
        }

        private void button11_Click(object sender, EventArgs e) {
         
            PrintLabel("Q20240129N2-0558", "重量12.8KG", DateTime.Now.Date.ToString("yyyy-MM-dd"), Nowkind);
        }

        private void textBox2_TextChanged(object sender, EventArgs e) {
            INIFileHelper.WriteIniValue("Setting", "heigth", textBox2.Text, Application.StartupPath + @"\Setting.ini");
            changed = true;
        }

        private void textBox3_TextChanged(object sender, EventArgs e) {
            INIFileHelper.WriteIniValue("Setting", "width", textBox3.Text, Application.StartupPath + @"\Setting.ini");
            changed = true;
        }
    }

}